package com.ymatou.iapi.liveseller.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.liveseller.parameter.RemoveProductVideoExplainBean;
import com.ymatou.iapi.liveseller.service.RemoveProductVideoExplainCall;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
import com.ymttest.utils.EnvSetup;
/**
*移除待讲解商品表Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_RemoveProductVideoExplain{
	private static RemoveProductVideoExplainBean removeproductvideoexplainBean;
	private static RemoveProductVideoExplainCall removeproductvideoexplainCall;
	private static LiveRoomWapper liveRoomWapper;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("移除待讲解商品表Test");
	}

	@Before
	public void caseUp() {
		removeproductvideoexplainBean=new RemoveProductVideoExplainBean();
		removeproductvideoexplainCall=new RemoveProductVideoExplainCall();
		liveRoomWapper=new LiveRoomWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(removeproductvideoexplainCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RemoveProductVideoExplain_001() {
		Logger.start(true,"求讲解之后，移除待讲解列表，成功");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String pid = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(sellerId));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			//求讲解
			LiveRoomCallService.AskProductVideo(createlive.getId(), pid, 1);
			JsonObject pve = LiveRoomCallService.GetUnExplainProductList(createlive.getId()).get(0).getAsJsonObject();
			int id = pve.get("Id").getAsInt();
			removeproductvideoexplainBean.setId(id);
			removeproductvideoexplainCall.setData(removeproductvideoexplainBean);
			removeproductvideoexplainCall.callService();			
			Logger.verifyEquals("200", removeproductvideoexplainCall.getString("Code"), "验证code");
			int size=LiveRoomCallService.GetUnExplainProductList(createlive.getId()).size();
			Logger.verifyEquals(size, 0, "待讲解商品为0");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RemoveProductVideoExplain_002() {
		Logger.start(true,"移除待讲解列表，id不对。失败");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String pid = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(sellerId));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			//求讲解
			LiveRoomCallService.AskProductVideo(createlive.getId(), pid, 1);
			JsonObject pve = LiveRoomCallService.GetUnExplainProductList(createlive.getId()).get(0).getAsJsonObject();
			int id = pve.get("Id").getAsInt();
			removeproductvideoexplainBean.setId(11223);
			removeproductvideoexplainCall.setData(removeproductvideoexplainBean);
			removeproductvideoexplainCall.callService();			
			Logger.verifyEquals("200", removeproductvideoexplainCall.getString("Code"), "验证code");
			int size=LiveRoomCallService.GetUnExplainProductList(createlive.getId()).size();
			Logger.verifyEquals(size, 1, "待讲解商品为1");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
}